<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="68px"
    >
      <el-form-item label="会员名" prop="customerName">
        <el-input
          v-model="queryParams.customerName"
          placeholder="请输入客户名"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="油品" prop="cardOilsType">
        <el-select
          v-model="queryParams.cardOilsType"
          placeholder="请选择油品"
          clearable
          size="small"
        >
          <el-option
            v-for="item in oilOptions"
            :key="item.dictValue"
            :label="item.dictLabel"
            :value="item.dictValue"
          ></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="充值时间" prop="">
        <el-date-picker
          v-model="dateRangeCreatedDate"
          type="daterange"
          unlink-panels
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <!-- <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">汇总</el-button> -->
        <!-- <el-button type="warning" icon="el-icon-download" size="mini" @click="handleExport" v-hasPermi="['customer:record:export']" >导出</el-button> -->
      </el-form-item>
    </el-form>
    <el-table :data="recordList">
      <el-table-column label="id" align="left" prop="id" v-if="false" />
      <el-table-column label="充值单号" align="left" prop="orderNo" />
      <el-table-column
        label="微信用户唯一标识"
        align="left"
        prop="unionId"
        v-if="false"
      />
      <el-table-column label="电子卡号" align="left" prop="customerNo" />
      <el-table-column label="会员名" align="left" prop="customerName" />
      <el-table-column
        label="油品"
        align="left"
        prop="cardOilsType"
        :formatter="cardOilsTypeFotmat"
      />
      <el-table-column
        label="电子会员卡消费充值类型：+，充值；-，消费；"
        align="left"
        prop="usageType"
        v-if="false"
      />
      <el-table-column label="充值金额" align="left" prop="amt" />
      <el-table-column label="余额" align="left" prop="balance" />
      <el-table-column
        label="消费方式"
        align="left"
        prop="payType"
        :formatter="payTypeFotmat"
      />
      <el-table-column
        label="油站ID"
        align="left"
        prop="stationId"
        v-if="false"
      />
      <el-table-column label="油站名称" align="left" prop="stationName" />
      <el-table-column
        label="油站名称"
        align="left"
        prop="create_time"
        v-if="false"
      />
    </el-table>
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import { listRecharge, exportRecharge } from "@/api/customer/recharge";

export default {
  name: "Record",
  data() {
    return {
      //创建订单时间间隔
      dateRangeCreatedDate: [],
      // 总条数
      total: 0,
      // 客户电子会员卡充值消费记录表格数据
      recordList: [],
      oilOptions: [],
      // 弹出层标题
      title: "",
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        customerName: null,
        usageType: "+",
        cardOilsType: null,
        status: 1,
      },
      // 表单参数
      form: {},
    };
  },
  created() {
    this.getList();
    this.getDicts("oil").then((response) => {
      this.oilOptions = response.data;
    });
  },
  methods: {
    payTypeFotmat(row, column) {
      if (row.payType === "1") {
        return "小程序";
      } else if (row.payType === "2") {
        return "POS";
      }
    },
    cardOilsTypeFotmat(row, column) {
      if (row.cardOilsType === "1") {
        return "汽油";
      } else if (row.cardOilsType === "2") {
        return "柴油";
      }
    },
    /** 查询客户电子会员卡充值消费记录列表 */
    getList() {
      listRecharge(
        this.addDateRange(this.queryParams, this.dateRangeCreatedDate)
      ).then((response) => {
        this.recordList = response.rows;
        this.total = response.total;
      });
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 导出按钮操作 */
    handleExport() {
      this.queryParams.stationId = this.$store.selectDeptId;
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有客户电子会员卡充值记录数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          return exportRecharge(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
        });
    },
  },
};
</script>
